<?php


$rid = intval($_GET['rid']);

if(edp_is_empty_string($rid) || !is_numeric($rid)) 
{
	edp_redirect(edp_href_link(PAGENAME_PAGE_NOT_FOUND));
}
	
	
$reviewDAO = GetReviewDAO();
$reviewResult = $reviewDAO->GetReviewInfo($rid);

if(!$reviewResult)
	edp_redirect(edp_href_link(PAGENAME_PAGE_NOT_FOUND));
	
	
$logid=GetLoginUserID(); 

$errmsg = GetMessageStack();
$userDAO=GetUserDAO();

function ShowPage()
{
	global $reviewDAO,$rid;
	$reviewDAO->UpdateReviewViewCount($rid);	
}

$responseContent = '';
function AddResponse()
{
	
    global $errmsg, $reviewDAO, $reviewResult,$logid, $responseContent;

     if($logid)
     {  
     	
     	$vcode = edp_db_input(trim($_POST['vcode']));	
     	
     	$userid=$logid;    
     	
     	$userip = getUserRealIPAddr();	
	    
     	$anonymous= edp_db_input(trim($_POST['post_author_type']));	
     	 
	    $response = edp_db_input(trim($_POST['response']));
	    
	    $responseContent = trim($_POST['response']);
     	
	    if($vcode!=edp_getsession('vcode'))
	    {
		    $errmsg->add( 'reg', '验证码无效!' );
		    return;
	     }      
	          
	    if( edp_is_empty_string($anonymous) || ($anonymous!='0'&&$anonymous!='1')){
		    $errmsg->add( 'reg', '无效类型' );
		    return;
	    } 	    	
	    	
 	
//     	$userid='0';
//        $anonymous = '1';	
//        $userip = getUserRealIPAddr();	
//        
//        $vcode = edp_db_input(trim($_POST['vcode']));	 
//        
//	    if($vcode!=edp_getsession('vcode'))
//	    {
//		    $errmsg->add( 'reg', '验证码无效!' );
//		    return;
//	     }               
//     
     
	
	     if( edp_is_empty_string($response)||strlen($response)>1000 ){
		    $errmsg->add( 'reg', '回应不能为空或者超过1000字!' );
		    return;
	     } 
	     
	     $res=$reviewDAO->InsertResponse($reviewResult['id'],$reviewResult['user_id'],$userid,$userip,$anonymous,$response);
	 	 if($res=='0')
		 {
			$errmsg->add( 'reg', '您在评论创建者的黑名单中，无法添加回应!' );
			return;
		 } 
	     if($res=='-1')
		 {
		    $errmsg->add( 'reg', '非法操作' );
			return;
		 }
		 
		 $responseContent = '';
		 
     }else{
     	
          $errmsg->add( 'reg', '非法操作!' );
	      return;
     } 
}

if(isset($_POST['action']))
	$action = $_POST['action'];
else
	$action='';	
	
if( $action=='addResponse' )
{	
	AddResponse();
}
	
ShowPage();


?>
